﻿using B.MES.Customer.Domain.DTO;
using DotNetCore.CAP;
using EventBusEto.Order;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Qiniu;
using Qiniu.Http;

namespace B.MES.Orders.Read.WebApi.Controllers
{
    /// <summary>
    /// 处理订单相关的 API 请求
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrdersController : ControllerBase
    {
        private readonly ICapPublisher _capPublisher;

        public OrdersController(ICapPublisher capPublisher)
        {
            _capPublisher = capPublisher;
        }
        /// <summary>
        /// 测试接口
        /// </summary>
        /// <returns>测试结果</returns>
        [HttpGet]
        public IActionResult Index()
        {
            return Ok(DateTime.Now);
        }
        ///// <summary>
        ///// 发布
        ///// </summary>
        ///// <param name="order">登录前台输入信息</param>
        ///// <returns>包含订单信息的 JSON 字符串</returns>
        //[HttpPost]
        //public IActionResult CreateOrder([FromBody] InputLogin order)
        //{
        //    //发布--生产者
        //    _capPublisher.Publish("OrderCreated", "aa");
        //    var json=Newtonsoft.Json.JsonConvert.SerializeObject(order);
        //    return Ok("输出结果："+json);
        //}
        /// <summary>
        /// 发布
        /// </summary>
        /// <param name="order">登录前台输入信息</param>
        /// <returns>包含订单信息的 JSON 字符串</returns>
        [HttpPost]
        public IActionResult CreateOrder([FromBody] InputLogin order)
        {

            //发布--生产者
            _capPublisher.Publish("OrderCreated", order);
            var json = Newtonsoft.Json.JsonConvert.SerializeObject(order);
            return Ok("输出结果：" + json);
        }
        //[HttpPost]
        //public void Test1()
        //{
        //    //发布消息，消息被订阅处理后，会回调到Test.Callback
        //    _capPublisher.Publish<string>("Test.Event", "Hello,World", "Test.Callback");
        //}
    }
}
